import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/admin/login',
    method: 'post',
    data: {
      ...data,
      contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
      headerAccept: 'application/json, text/plain, */*'
    }
  })
}

export function getInfo(token) {
  return new Promise((resolve, reject) => {
    request({
      url: '/admin'
    }).then(res => {
      if (+res.errCode === 0) {
        resolve({
          data: {
            roles: ['superAdmin'],
            introduction: '我是管理员',
            avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
            name: 'admin'
          }
        })
      } else {
        reject('检测失败，退出登录')
      }
    })
  })
}

export function logout() {
  return new Promise(resolve => {
    resolve({
      'data': null,
      'errCode': 500,
      'errMsg': 'OK'
    })
  })
}

export const getUserList = (data) => {
  return request({
    url: '/mall/adminUser',
    method: 'get',
    params: data
  })
}

export const postUserStatus = (data, method) => {
  return request({
    url: '/mall/adminUser',
    method,
    params: data
  })
}

export const postUserData = (data) => {
  return request({
    url: '/mall/adminUser',
    method: 'post',
    data
  })
}

export const getEditUserData = (id) => {
  return request({
    url: `/mall/adminUser/${id}`,
    method: 'get'
  })
}
